<?php
/**
 * clase para el manipuleo de usuarios
 * se Adapto a la Tabla "usuarios" los atributos publicos corresponden a los campos en la tabla "usuarios"
 * @author rootciv
 * @author tuadmin
 * @version 1.1.1
 */
class systemUser
{
	public $registered = false;//este es especial se usa para comprobar los usuarios registrados y los que no lo estan
	
	public $id_user = 0;
	public $usuario ="guest";
	public $nombre = 'guest';
	public $email;
	public $passwd = null;
	public $fecAlt = null;
	
	public $active = 1;
	private $parameters;
	private $TMP = "";
	private $_token = null;
	private $_persitente = array();
	public $__destroy = false;
	public function __construct($alternative_nick = null)
	{
		$this->nick = empty($this->nick)? $alternative_nick : $this->nick;
		$this->_token = rand((int)$this->id_user + 100, 999 +(int)$this->id_user);
	}
	public function generateToken()
	{
		$this->_token = rand((int)$this->id_user + 100, 999 +(int)$this->id_user);
	}
	public function getToken()
	{
		return $this->_token;
	}
	/**
	 * Limpia los datos los inicializa
	 */
	public function erase()
	{
			$this->id_user = 0;
			$this->registered = false;
			$this->nombre = null;
			$this->email = null;
			$this->password = null;
			$this->active = 1;
	}
	public function loadData($array)
	{
		if(is_array($array))
		{
			foreach($array as $clave => $valor)
			{
				$this->{$clave} = $valor;
			}
		}
	}
	public function get($key,$default = null)
	{
		if(isset($this->_persistente[$key]))
		{
			return $default;
		}
	}
	public function set($key,$value)
	{
		$this->_persistente[$key] = $value;
	}
	public function export()
	{
		return $this->_persistente;
	}
	public function import($import)
	{
		$this->_persistente = $import;
	}
	public function __destruct()
	{
		if($this->__destroy)
		{
			
		}
		else
		{
			XAUTH::persitent($this);
		}
	}
}